package com.lv.LvRefundRecord.web;
import com.aqgj.User.bean.User;
import com.aqgj.util.JsonWrapper;
import com.lv.LvRefundRecord.bean.LvRefundRecord;
import com.lv.LvRefundRecord.service.LvRefundRecordManager;
import com.lv.LvTourismOrder.bean.LvTourismOrder;
import com.lv.LvTourismOrder.service.LvTourismOrderManager;
import com.ztc.ZtcTransport.bean.ZtcTransport;
import com.ztc.ZtcTransport.service.ZtcTransportManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
@Controller
@RequestMapping("LvRefundRecord")
public class LvRefundRecordAction {
    @Autowired
    private LvRefundRecordManager lvRefundRecordManager;
    @Autowired
    private ZtcTransportManager ztcTransportManager;
    @Autowired
    private LvTourismOrderManager lvTourismOrderManager;

    /**
     * 获取当前公司旅游订单退款列表.
     * @param pageNo    页码
     * @param pageSize  条数
     * @param session
     * @return
     */
    @RequestMapping("getRecordSumAndList")
    @ResponseBody
    public HashMap<String,Object> getRecordSumAndList(int pageNo, int pageSize, HttpSession session) {
        User user=(User)session.getAttribute("userInfo");
        ZtcTransport ztcTransport=ztcTransportManager.get(user.getTransportId());
        if(ztcTransport==null){
            return JsonWrapper.failureWrapperMsg("信息获取失败，请稍后重试！");
        }
        List<Object> list = lvRefundRecordManager.getRecordList(pageNo,pageSize,ztcTransport.getId());
        return JsonWrapper.successPagerWrapper(list,lvRefundRecordManager.getSqlSumQuery(ztcTransport.getId()));
    }

    /**
     * 获取旅游订单退款记录详情.
     * @param rid  退款记录id
     * @return
     */
    @RequestMapping("getRecordInfo")
    @ResponseBody
    public HashMap<String,Object>  getRecordInfo(String rid) {
        LvRefundRecord lvRefundRecord=lvRefundRecordManager.get(rid);
        if(lvRefundRecord==null){
            return JsonWrapper.failureWrapperMsg("信息获取失败，请稍后重试！");
        }
        LvTourismOrder lvOrder= lvTourismOrderManager.get(lvRefundRecord.getFkLvOrderId());
        if(lvOrder==null){
            return JsonWrapper.failureWrapperMsg("订单数据异常，请稍后重试！");
        }
        return lvRefundRecordManager.getRecordInfo(rid);
    }
}